package com.lbj1.aopannotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//增强的类
@Component
@Aspect  /*aspectJ依赖有效范围设置成compile*/
@Order(3)
public class UserProxy {

    @Pointcut(value = "execution(* com.lbj1.aopannotation.User.add(..))")
    public void point(){

    }

    //前置通知   @Before 注解表示作为前置通知
    @Before(value = "point()")
    /*add()方法之前执行before方法1*/
    public void before(){
        System.out.println("before......");
    }

    /*最终通知 异常也执行*/
    @After(value = "execution(* com.lbj1.aopannotation.User.add(..))")
    public void after(){
        System.out.println("after.......");
    }

    /*后置通知  返回结果后通知 异常不通知 */
    @AfterReturning(value = "execution(* com.lbj1.aopannotation.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning.......");
    }

    /*异常通知*/
    @AfterThrowing(value = "execution(* com.lbj1.aopannotation.User.add(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing.......");
    }

    /*环绕通知  异常后一个不执行*/
    @Around(value = "execution(* com.lbj1.aopannotation.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前.......");

        //被执行的方法执行
        proceedingJoinPoint.proceed();

        System.out.println("环绕之后.......");
    }

}
